/**
 * 属性特征值维护 - 编辑页面
 * @author shixc
 * @date 2018/01/11
 */
define(function () {
    var self,
        app = win.app,
        doc = document,
        vueData = {
            isAdd: false,
            isDetail: false,
            form: '',
            rules: {
                GWAJ001: [
                    {required: true, message: '不可为空', trigger: 'change'}
                ],
                GWAJ002: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWAJL004: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWAJL005: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWAJACTI: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ]
            },
            selectOptions: {
                sys_y_n: app.datas_("sys_y_n"),
                options: []
            }
        },
        callObj,
        pageVue,
        layOpenIndex
    ;

    var Gwai270Edit = app.Module.extend({
        init: function () {
            self = this;
            self._super({
                _tag: 'gwai270_edit',
                _loadTplsFull: [{
                    dom: 'common_open_window', tpl: 'common/_open_window'
                }]
            }, win);
        },
        edit: function () {
            app.ajax({
                xurl: 'crm/gwai270/edit',
                xdata: vueData.form,
                loading: true,
                okmsg: '属性特征值信息修改成功',
                cb: function (result) {
                    if (result.ok) {
                        //同步更新缓存对应的值
                        //callObj.update(result.xdata);
                        app.pageModule('gwai270').reloadTableCurr();
                        layer.close(layOpenIndex);
                    }
                }
            });
        },
        add: function () {
            app.ajax({
                xurl: 'crm/gwai270/add',
                xdata: vueData.form,
                loading: true,
                okmsg: '属性特征值信息保存成功',
                cb: function (result) {
                    if (result.ok) {
                        app.pageModule('gwai270').reloadTableCurr();
                        layer.close(layOpenIndex);
                    }
                }
            });
        },
        _call: function (obj) {
            pageVue.$refs['form'].resetFields();
            layOpenIndex = obj.layOpenIndex;
            callObj = obj.obj;
            if(obj.is_detail){
                vueData.isDetail = true;
            }else {
                vueData.isDetail = false;
            }
            if (obj.is_add) {
                vueData.isAdd = true;
                app.extendUpLow({
                    target: vueData.form,
                    res: {
                        GWAJACTI: 'Y'
                    },
                    reset: true
                });
            } else {
                vueData.isAdd = false;
                app.extendUpLow({
                    target: vueData.form,
                    res: callObj.data,
                    reset: true
                });
            }

        },
        _ready: function () {
            vueData.form = app.fields_(['GWAJ']);
            pageVue = new Vue({
                el: '#gwai270_edit',
                data: vueData,
                methods: {
                    cancel: function () {
                        layer.close(layOpenIndex);
                    },
                    sure: function () {
                        this.$refs['form'].validate(function (valid) {
                            if (valid) {
                                if (vueData.isAdd) {
                                    self.add();
                                } else {
                                    self.edit();
                                }
                            }
                        });
                    },
                    opensxtz: function () {
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method: 'q_gwai001',
                                    columnList: [
                                        {label: '属性特征分类编号', prop: 'GWAI001', width: '150'},
                                        {label: '说明', prop: 'GWAIL003', width: '150'},
                                        {label: '助记码', prop: 'GWAIL004', width: '150'}
                                    ],
                                },
                                cb: function (data) {
                                    vueData.form.GWAJ001 = data.GWAI001;
                                },
                            },
                            index: 0,
                            openOpts: {
                                title: '选择属性特征分类',
                                area: ['600px', '470px']
                            }
                        });
                    }
                },
                created: function () {
                    self._setEleIsReady('gwai270_edit');
                }
            });
        },
        _lazy: function () {
            app.ajax({
                xurl: 'crm/gwai270/getGwaiList',
                cb: function (result) {
                    vueData.selectOptions.options = result.data.list;
                }
            });
            this._super();
        }
    });

    return new Gwai270Edit();

});